package com.yehui.guava.concurrent;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.TimeUnit;

/**
 * @author 业徽
 * @date 2021/7/22
 */
public class WarmUpRateLimiterDemo {

    public static void main(String[] args) {
        final RateLimiter rateLimiter = RateLimiter.create(50, 30, TimeUnit.SECONDS);

        rateLimiter.acquire(50);
        double sum = 0;
        while (true) {
            final double acquire = rateLimiter.acquire(50);
            sum += acquire;
            System.out.printf("acquire: %s, sum: %s%n", acquire, sum);

            if (acquire <= 1) {
                break;
            }
        }

    }

}
